package com.im.app.manager;


import com.im.app.model.User;
import org.jim.core.cache.redis.JedisTemplate;

import java.util.*;

public class UserManager {

    private static UserManager manager;

    private List<String> userBlackIds = new ArrayList<>();

    public UserManager(){

    }




//    public Map<String, User> kefuUser = new HashMap<>();

    public static UserManager getManager(){
        if(manager == null){
            synchronized (UserManager.class){
                if(manager == null){
                    manager = new UserManager();
                }
            }
        }
        return manager;
    }


    public void cacheKefuUser(String key,User user){
        try {
            JedisTemplate.me().set(key,user,60*60*24);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public void addUserBlack(String userId){
        if (!userBlackIds.contains(userId)){
            userBlackIds.add(userId);
        }
    }
    public void removeUserBlack(String userId){
        userBlackIds.remove(userId);
    }

    public boolean isBlack(String userId){
        return userBlackIds.contains(userId);
    }



}
